package proxy;

import org.junit.Test;
import proxy.cglib.AliSmsService;
import proxy.cglib.CglibProxyFactory;
import proxy.jdk.JdkProxyFactory;
import proxy.staticProxy.SmsProxy;
import proxy.staticProxy.SmsService;
import proxy.staticProxy.SmsServiceImpl;

/**
 * author : yeswater
 * date : 2023/7/15
 */

public class ProxyTest {

    /**
     * 静态代理
     */
    @Test
    public void test() {
        SmsService smsService = new SmsServiceImpl();
        SmsProxy smsProxy = new SmsProxy(smsService);
        smsProxy.send("Lucas");
    }

    /**
     * jdk
     */
    @Test
    public void test1() {
        System.out.println(JdkProxyFactory.getProxy(new SmsServiceImpl()));
        // SmsService smsService = (SmsService) JdkProxyFactory.getProxy(new SmsServiceImpl());
        // smsService.send("Lucas");
    }

    /**
     * cglib
     */
    @Test
    public void test2() {
        // System.out.println(CglibProxyFactory.getProxy(AliSmsService.class).getClass());
        AliSmsService aliSmsService = (AliSmsService) CglibProxyFactory.getProxy(AliSmsService.class);
        aliSmsService.send("Lucas");
    }

}
